﻿using System;
using System.Net;
using Microsoft.SharePoint.Client;

namespace SharePointOnline.Helper.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            String siteCollectionUrl = "https://lgkev.sharepoint.com/sites/test";
            String login = "login@test.onmicrosoft.com";
            String password = "*********";

            //Authenticate for client object model
            ClientContext clientContext = Authenticator.GetClientContext(siteCollectionUrl, login, password);
            Web site = clientContext.Web;
            clientContext.Load(site);
            clientContext.ExecuteQuery();
            Console.WriteLine("Title: {0}", site.Title);

            //Authenticate for web usage
            CookieContainer cookies = Authenticator.GetAuthenticatedCookies(siteCollectionUrl, login, password);

            //Test solution deactivation, upload, and activation
            Console.WriteLine("Deactivating solution");
            SandboxSolutions.DeactivateSolution(siteCollectionUrl, cookies, "ANO.SPImageFieldUpload.Sandbox.wsp");
            Console.WriteLine("Uploading solution");
            SandboxSolutions.UploadSolution(siteCollectionUrl, cookies, "ANO.SPImageFieldUpload.Sandbox.wsp");
            Console.WriteLine("Activating solution");
            SandboxSolutions.ActivateSolution(siteCollectionUrl, cookies, "ANO.SPImageFieldUpload.Sandbox.wsp");

        }
    }
}
